﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Register.BLL;
using Register.Model;
using System.Web.Script.Serialization;

namespace RegisterWeb.Manager
{
    /// <summary>
    /// MenuService 的摘要说明
    /// </summary>
    public class MenuService : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            MenuListService mls = new MenuListService();
          
            Menus menus = new Menus();
            menus.menus = new List<Menu>();
            foreach (ModuleTopInfo mti in mls.ModuleTopInfoList)
            {
                Menu menu = new Menu();
                menu.icon = "icon-sys";
                menu.menuid = mti.ModuleTop_ID;
                menu.menuname = mti.ModuleTop_Name;
                menu.menus = new List<MenuItem>();
                foreach (ModuleInfo mi in mti.ModuleInfoList)
                {
                    menu.menus.Add(new MenuItem(mi.ModuleInfo_ID,mi.ModuleInfo_Name,"icon-nav",mi.ModuleInfo_Page));
                }
                menus.menus.Add(menu);
            }
            JavaScriptSerializer jss = new JavaScriptSerializer();
            context.Response.Write(jss.Serialize(menus));


        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

    class Menus
    {
        public List<Menu> menus { get; set; }
    }
    class Menu
    {
        public string menuid { get; set; }
        public string menuname { get; set; }
        public string icon { get; set; }
        public List<MenuItem> menus { get; set; }
    }
    class MenuItem
    {
        public MenuItem(string menuid, string menuname, string icon, string url)
        {
            this.menuid = menuid;
            this.menuname = menuname;
            this.icon = icon;
            this.url = url;
        }
        public string menuid { get; set; }
        public string menuname { get; set; }
        public string icon { get; set; }
        public string url { get; set; }
    }
}